<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="" id="loanSearchForm" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
					<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">贷款编号:</label>
							<div class="search_input">
								<input type="text" name="loanId" placeholder="请输入贷款编号">
							</div>
						</div>
					<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="custId" type="text" name="custId" placeholder="请输入商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="custName" type="text" name="custName" placeholder="请输入商户名称">
							</div>
						</div>
						<!-- <div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户手机:</label>
							<div class="search_input">
								<input id="usrMobile" type="text" name="custLogin"
									placeholder="请输入商户手机">
							</div>
						</div> -->
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">贷款状态:</label>
							<div class="search_input">
							<select 
								rel="obj.LOANSTATUS"
								location="local" 
								 name="loanStatus" 
								  style="width: 120px;vertical-align:middle;">
								  <option value="">---请选择---<option>
						 </select>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">审核状态:</label>
							<div class="search_input">
							<select 
								rel="obj.LOANAUDITSTATUS"
								location="local" 
								 name="auditStatus" 
								 id="auditStatus" 
								 style="width: 120px;vertical-align:middle;">
								 <option value="">---请选择---<option>
						 </select>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px;margin-right: 15px;width: 280px;">
						    <label class="label_search" for="userName">申请时间:</label>
							<div class="input-group">
								<input type="text" class="form-control date-picker"  name="loanDateStart" data-date-format="yyyy-mm-dd" placeholder="起始日期" />
								<span class="input-group-addon">
									<i class="fa fa-exchange"></i>
								</span>
								<input type="text" class="form-control date-picker"  name="loanDateEnd" data-date-format="yyyy-mm-dd" placeholder="结束日期" />
							</div>

						</div>
						
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索">
								搜索
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style="display: block;" class="widget-body " id="total">
		
	</div>
	</form>
	
	
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			
			<div style="margin-top: 10px">
				 <span id="paging_bar" style="float: right"> </span>
			</div>
			<span id="auth_btn">
				
				<!-- <a class='btn btn-small btn-warning'
					onclick="rechargeDetails();"> 详细
				</a> -->
				<!-- <a  class="btn btn-small btn-info"
					onclick="">导出数据文件
				</a> -->
				</span>
			 <span id="paging_bar" style="float: right"> </span>
			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
	var jqGrid;
	jQuery(function($) {
		var grid_selector = "#grid-table";
		var pager_selector = "#grid-pager";

		$(window).on(
				'resize.jqGrid',
				function() {
					$(grid_selector).jqGrid('setGridWidth',$(".page-content").width());
				})
		var parent_column = $(grid_selector).closest('[class*="col-"]');
		$(document).on(
				'settings.ace.jqGrid',
				function(ev, event_name, collapsed) {
					if (event_name === 'sidebar_collapsed'|| event_name === 'main_container_fixed') {
						setTimeout(function() {
							$(grid_selector).jqGrid('setGridWidth',parent_column.width());
						}, 0);
					}
				})
		jQuery(grid_selector).jqGrid({
			url : "mpomng/loan/query.do",
			datatype : "json",
			height : '100%',
			width : '100%',
			colNames : [ '贷款编号','商户编号  ','商户名称','申请时间','贷款状态','申请额度','实际发放额度','应还金额','实际还款金额','申请说明','审核状态','审核描述','发放日期','还款日期','操作' ],
			colModel : [ {name : 'loanId',        index : 'loanId',        width : '140px',sortable:false }, 
					     {name : 'custId',        index : 'custId',        width : '120px',sortable:false }, 
					     {name : 'custName',        index : 'custName',        width : '80px',sortable:false },
					     {name : 'createTime',        index : 'createTime',        width : '140px',sortable:false,formatter : gridFormatByDate },
					     {name : 'loanStatus',        index : 'loanStatus',        width : '100px',sortable:false ,ditcKey:'LOANSTATUS' ,formatter : gridFormatByDict },
					     {name : 'applyForAmt',        index : 'applyForAmt',        width : '100px',sortable:false, formatter :  cent2Yuan}, 
					     {name : 'realityAmt',        index : 'realityAmt',        width : '100px',sortable:false, formatter :  cent2Yuan }, 
					     {name : 'refundAmt',        index : 'refundAmt',        width : '100px',sortable:false,formatter :  cent2Yuan}, 
					     {name : 'giveBackAmt',        index : 'giveBackAmt',        width : '100px',sortable:false,formatter :  cent2Yuan }, 
					     {name : 'loanDesc',        index : 'loanDesc',        width : '100px',sortable:false }, 
					     {name : 'auditStatus',        index : 'auditStatus',        width : '100px',sortable:false ,ditcKey:'LOANAUDITSTATUS', formatter:gridFormatByDict }, 
					     {name : 'auditDesc',        index : 'auditDesc',        width : '100px',sortable:false  }, 
					     {name : 'issuedTime',        index : 'issuedTime',        width : '80px',sortable:false,formatter : dtFormat } ,
					     {name : 'refundTime',        index : 'refundTime',        width : '80px',sortable:false,formatter : dtFormat } ,
					     {name : '',        index : '',        width : '100px',sortable:false,formatter:operateEdit} 
			            ],
			viewrecords : true,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			altRows : true,

			shrinkToFit : false,
			multiselect : false,//设置行可多选的 
			multiboxonly : true,//

			loadComplete : function() {
				var table = this;
				setTimeout(function() {
					//加载分页
					initPagingBar(grid_selector);
				}, 0);
			},
			beforeRequest : function() {//请求之前执行
				jqGrid = this;
			},
		});
		$(window).triggerHandler('resize.jqGrid');

		$(document).one('ajaxloadstart.page', function(e) {
			$(grid_selector).jqGrid('GridUnload');
			$('.ui-jqdialog').remove();
		});
	
		
		
	 	function operateEdit(cellvalue, options, rowObject){//定义button按钮
			var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  
				button += "<button class='btn btn-xs btn-warning' onclick='editLoan(\""+rowObject["loanId"]+"\")'"   
				 +"title='编辑'>编辑</button>";
				 
				if(rowObject["auditStatus"] === '00'){//未审核的添加审核按钮
					button += "<button class='btn btn-xs btn-warning' onclick='auditLoan(\""+rowObject["loanId"]+"\")'"   
					 +"title='审核'>审核</button>";
				}
				
// 				 if(rowObject["payCardNo"] != undefined && rowObject["checkStatus"] != 0 && rowObject["checkStatus"] != 1){
// 					 button += "<button class='btn btn-xs btn-warning' onclick='examineDetails(\""+rowObject["payCardNo"]+"\",\""+rowObject["prdOrdNo"]+"\")'"   
// 					 +"title='审核信息查看'>审核</button>";
// 				 }
			return button;
		};
	});
	
	function editLoan(loanId) {
		 /* if(loanId.length<=0){
			msg.alert("警告", "当前没有选择数据项！", "error");
			return;
		} */
		
		if(!loanId){
			msg.alert("错误", "无法编辑", "error");
			return;
		}
		 
		//var scrWidth = document.body.scrollWidth;
		openDialog({
			dialogId : 'dlg-loanEdit',
			title : '编辑贷款记录',
			pageUrl :'mpomng/loan/loanEditView.do',
			dataUrl : 'mpomng/loan/loanInf.do',
			width : '80%',
		    height:'80%',
			dataParam : {
				loanId : loanId
			},
			dataName : 'obj,map'//表单数据存储对象名称
		}); 
		
	}
	
	
	function auditLoan(loanId){
		if(!loanId){
			msg.alert("错误", "无法编辑", "error");
			return;
		}
		 
		//var scrWidth = document.body.scrollWidth;
		openDialog({
			dialogId : 'dlg-auditLoan',
			title : '审核贷款记录',
			pageUrl :'mpomng/loan/loanAuditView.do',
			dataUrl : 'mpomng/loan/loanInf.do',
			width : '80%',
		    height:'80%',
			dataParam : {
				loanId : loanId
			},
			dataName : 'obj,map'//表单数据存储对象名称
		}); 
	}

	</script>